{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/luntan_vote/index')}">投票管理</a></li>
            <li class=""><a href="{:url('admin/luntan_vote/add')}">添加投票</a></li>
            <li class="layui-this">编辑投票</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/luntan_vote/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属栏目</label>
                        <div class="layui-input-block">
                            <select name="cid" lay-verify="required">
                                {foreach name="categorylist" item="vo"}
                                <option value="{$vo.id}" {if condition="$vote.cid==$vo.id"} selected="selected"{/if}>{neq name="vo.level" value="1"}|{php}for($i=1;$i<$vo['level'];$i++){echo ' ----';}{/php}{/neq} {$vo.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">投票标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="{$vote.name}" required  lay-verify="required" placeholder="请输入投票标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="显示"   {if condition="$vote.status==1"} checked="checked"{/if}>
                            <input type="radio" name="status" value="0" title="未显示" {if condition="$vote.status==0"} checked="checked"{/if}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">投票类型</label>
                        <div class="layui-input-block">
                            <input type="radio" name="type" value="1" title="多选" {if condition="$vote.status==1"} checked="checked"{/if}>
                            <input type="radio" name="type" value="0" title="单选" {if condition="$vote.status==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    
                    {foreach name="vote.select" item="vo"}
                    <div class="layui-form-item">
                        <label class="layui-form-label">投票选项</label>
                        <div class="layui-input-block">
                            <input type="text"   name="select[]" value="{$vo.name}" class="layui-input layui-input-inline">
                            <input type="hidden" name="ids[]" value="{$vo.id}" class="layui-input layui-input-inline">
                            <input type="button" value="删除" class="layui-btn layui-btn-primary shanchu">
                            <input type="button" value="添加" class="layui-btn layui-btn-primary tianjia">
                        </div>
                    </div>
                    {/foreach}
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="create_time" value="{$vote.create_time}" class="layui-input datetime">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$vote.id}">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/kindeditor/kindeditor.config.js"></script>
<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>
{/block}
{block name="script"}
<script>
    $(document).ready(function () {
        var _kindEditor;
        KindEditor.ready(function(K) {
            _kindEditor = K.create('#content', KindEditorOptions);

            K('#upload-photo-btn').click(function () {
                var photo_list_item = '';
                _kindEditor.loadPlugin('multiimage', function() {
                    _kindEditor.plugin.multiImageDialog({
                        showRemote : false,
                        imageUrl : K('#photo').val(),
                        clickFn : function(data) {
                            $.each(data, function (index, item) {
                                photo_list_item += '<div class="photo-list"><input type="text" name="photo[]" value="' + item.url + '" class="layui-input layui-input-inline">';
                                photo_list_item += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>'
                            });
                            $('#photo-container').append(photo_list_item);
                            _kindEditor.hideDialog();
                        }
                    });
                });
            });
        });

        $('#photo-container').on('click', '.remove-photo-btn', function () {
            $(this).parent('.photo-list').remove();
        });
    });
</script>

<script>
        $('.tianjia').click(function(e) {
            var html=$('<div class="layui-form-item"><label class="layui-form-label">投票选项</label><div class="layui-input-block"><input type="text" name="select[]" value="" class="layui-input layui-input-inline" id="thumb"><input type="button" name="" value="删除" class="layui-btn layui-btn-primary shanchu"></div></div>');
           $(this).parents('.layui-form-item').parent().find('.layui-form-item:last').prev().before(html);
        }); 
        $('.layui-form').on('click','.shanchu',function(){
            $(this).parents('.layui-form-item').remove();
        })
</script>
{/block}